<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>属性监视</title>
</head>
<body>


    <div id="root">
      <h2>灯{{bulbStatus}}</h2>
       <button @click="isLight=!isLight">{{btnValue}}</button> 
    </div>
    



   <script>
   let app =  new Vue({
        el:'#root',
        data:{
          isLight: false
        },
        methods: {
            
        },
        computed:{
          bulbStatus(){
            return this.isLight? '亮':'灭'
          },
          btnValue(){
            return this.isLight? '关灯':'开灯'
          }    
        },
        watch:{
          isLight(newValue,oldValue){
            console.log(`灯的状态改变了:${oldValue}->${newValue}`)
          },
          bulbStatus(newValue,oldValue){
            console.log(`灯的状态改变了:${oldValue}->${newValue}`)
          }     
        }
    })

    app.$watch('btnValue',function(newValue,oldValue){
        console.log(`灯的状态改变了:${oldValue}->${newValue}`)
    })

   </script> 
</body>
</html>